#include "pthread.h"
#include <stdio.h>
#include <unistd.h>

void *first_handle(void *)
{
    for (int i = 0; i < 5; i++)
    {
        printf("first:%d\n", i);
        sleep(1);
    }
}

void *second_handle(void *)
{
    for (int i = 0; i < 5; i++)
    {
        printf("second:%d\n", i);
        sleep(2);
    }
}

int main(int argc, char const *argv[])
{
    pthread_t first;
    pthread_t second;
    pthread_create(&first, NULL, first_handle, NULL);
    pthread_create(&second, NULL, second_handle, NULL);
    // 1秒后取消子线程
    pthread_cancel(first);

    // 等待子线程终止并获取其退出状态
    pthread_join(second, NULL);

    // sleep(10);
    return 0;
}
